//
//  MainViewController.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/8/30.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "MainViewController.h"
#import "MainCollectionViewCell.h"
#import "TAMacro.h"
#import "BmlTabBarController.h"
@interface MainViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)NSArray *array;
@property (nonatomic,strong)MainCollectionViewCell * first;
@property (nonatomic, strong)UICollectionView *collectionView;

@end

@implementation MainViewController
-(NSArray *)array{
    if (!_array) {
        self.array = @[@"背景一",@"背景二",@"背景三",@"背景四"];
        
    }
    return _array;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    [self foundCollectionView];
}
-(void)foundCollectionView{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); // 内边距
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    [self.view addSubview:_collectionView];
    
    // 注册cell
    
    [self.collectionView registerClass:[MainCollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"return" forIndexPath:indexPath];
    
    cell.cycleImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",self.array[indexPath.row]]];
    cell.backgroundColor =  [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0];
    if (indexPath.row == 3) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(SCREEN_WIDTH/ 3, SCREEN_HEIGHT / 3 *2, SCREEN_WIDTH/3, SCREEN_HEIGHT/8);
        [button setTitle:@"点击进入" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:0.971 green:0.256 blue:0.819 alpha:1.000] forState:UIControlStateNormal];
        button.layer.borderWidth = 2;
        button.layer.cornerRadius = 5;
        button.clipsToBounds = YES;
        button.layer.borderColor = [UIColor whiteColor].CGColor;
        
        [cell addSubview:button];
        [button addTarget:self action:@selector(clickMethods:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    return cell;
}
- (void)clickMethods:(UIButton *)sender {
    BmlTabBarController *ltab = [[BmlTabBarController alloc]init];
    [self presentViewController:ltab animated:YES completion:^{
        
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
